/**
 * 
 */
package com.alkandros.descuentosperu;

import com.alkandros.descuentosperu.constants.IAppConstants;
import com.alkandros.descuentosperu.manager.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * @author Jiju Induchoodan
 *
 */
public class SubMenuActivity extends Activity implements IAppConstants {

	private int item;
	LinearLayout linearLayout;
	private String [] items;
	private String [] urls;
	Button button [];
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_submenu);
		Bundle extras= getIntent().getExtras();
		if(extras!=null)
		{
			item =extras.getInt("TYPE");
		}
		linearLayout  = (LinearLayout)findViewById(R.id.linearLayoutRoot);
		
		
		getActionBar().setDisplayShowTitleEnabled(true);
		getActionBar().setTitle(getResources().getStringArray(R.array.menu_array)[item-1]);
		
		switch (item) {
		case 1:
			items= getResources().getStringArray(R.array.coupons_array);
			urls= getResources().getStringArray(R.array.coupons_urls);
			
			break;
		case 2:
			items= getResources().getStringArray(R.array.supermarkets_array);
			urls= getResources().getStringArray(R.array.supermarkets_urls);
			
			break;
		case 3:
			items= getResources().getStringArray(R.array.retails_array);
			urls= getResources().getStringArray(R.array.retails_urls);
			break;
		case 4:
			items= getResources().getStringArray(R.array.fastfood_array);
			urls= getResources().getStringArray(R.array.fastfood_urls);
			break;

		default:
			break;
		}
		
		for (int i = 0; i < items.length; i++) {
			
			final int pos=i;
			button = new Button[items.length];
			button[i] = new Button(this);
			button[i].setText(items[i]);
			button[i].setId(i);
			
			button[i].setBackgroundResource(R.drawable.rounded_button);
			button[i].setTextColor(getResources().getColor(R.color.red));
			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Utils.getWidth(this)-200, 
					LinearLayout.LayoutParams.WRAP_CONTENT);
			params.setMargins(0, 20, 0, 0);
			button[i].setLayoutParams(params);
		//	Log.e("", "Button width"+button.getWidth()+"measure width"+button.getMeasuredWidth());
			linearLayout.addView(button[i]);
			
			button[i].setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					WebViewActivity.openActivity(SubMenuActivity.this, urls,items,pos);
					
				}
			});
		}
	}
	public static void openActivity(Context context,int pos)
	{
		Intent intent = new Intent(context,SubMenuActivity.class);
		intent.putExtra("TYPE",pos);
		context.startActivity(intent);
		
	}

}
